$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'order/userpayment/list',
        datatype: "json",
        colModel: [			
			{ label: 'paymentId', name: 'paymentId', index: 'payment_id', width: 50, key: true },
			{ label: '支付金额', name: 'money', index: 'money', width: 80 }, 			
			{ label: '支付货币金额', name: 'curMoney', index: 'cur_money', width: 80 }, 			
			{ label: '会员用户名', name: 'memberId', index: 'member_id', width: 80 }, 			
			{ label: '支付状态', name: 'status', index: 'status', width: 80 }, 			
			{ label: '', name: 'payName', index: 'pay_name', width: 80 }, 			
			{ label: '支付类型', name: 'payType', index: 'pay_type', width: 80 }, 			
			{ label: '支付完成时间', name: 'tPayed', index: 't_payed', width: 80 }, 			
			{ label: '操作员', name: 'opId', index: 'op_id', width: 80 }, 			
			{ label: '支付单唯一编号', name: 'paymentBn', index: 'payment_bn', width: 80 }, 			
			{ label: '收款账号', name: 'account', index: 'account', width: 80 }, 			
			{ label: '收款银行', name: 'bank', index: 'bank', width: 80 }, 			
			{ label: '支付账户', name: 'payAccount', index: 'pay_account', width: 80 }, 			
			{ label: '货币', name: 'currency', index: 'currency', width: 80 }, 			
			{ label: '支付网关费用', name: 'paycost', index: 'paycost', width: 80 }, 			
			{ label: '支付方式名称', name: 'payAppId', index: 'pay_app_id', width: 80 }, 			
			{ label: '支付版本号', name: 'payVer', index: 'pay_ver', width: 80 }, 			
			{ label: '支付IP', name: 'ip', index: 'ip', width: 80 }, 			
			{ label: '支付开始时间', name: 'tBegin', index: 't_begin', width: 80 }, 			
			{ label: '支付确认时间', name: 'tConfirm', index: 't_confirm', width: 80 }, 			
			{ label: '支付注释', name: 'memo', index: 'memo', width: 80 }, 			
			{ label: '支付返回地址', name: 'returnUrl', index: 'return_url', width: 80 }, 			
			{ label: '支付单状态', name: 'disabled', index: 'disabled', width: 80 }, 			
			{ label: '支付单交易编号', name: 'tradeNo', index: 'trade_no', width: 80 }, 			
			{ label: '第三方支付账户', name: 'thirdpartyAccount', index: 'thirdparty_account', width: 80 }, 			
			{ label: '支付渠道', name: 'source', index: 'source', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		userPayment: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.userPayment = {};
		},
		update: function (event) {
			var paymentId = getSelectedRow();
			if(paymentId == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(paymentId)
		},
		saveOrUpdate: function (event) {
			var url = vm.userPayment.paymentId == null ? "order/userpayment/save" : "order/userpayment/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.userPayment),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var paymentIds = getSelectedRows();
			if(paymentIds == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "order/userpayment/delete",
                    contentType: "application/json",
				    data: JSON.stringify(paymentIds),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(paymentId){
			$.get(baseURL + "order/userpayment/info/"+paymentId, function(r){
                vm.userPayment = r.userPayment;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});